<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
    ">
    <title>查询结果</title>
    <link rel="stylesheet" href="../assets/css/dropload.css"/>
    <style type="text/css">
        html, body {
            margin: 0;
            padding: 0;
            font-family: Arial, 'Microsoft YaHei';
        }

        body {
            font-size: 0.6rem;
            padding-left: 0.7rem;
            padding-right: 0.7rem;
            letter-spacing: 1px;
        }

        .header {
            font-size: 1rem;
            text-align: center;
            padding-top: 0.9rem;
            padding-bottom: 0.9rem;
        }

        .result-item {
            display: flex;
            padding-top: 0.8rem;
            padding-bottom: 0.8rem;
            padding-left: 0.5rem;
            padding-right: 0.3rem;
            border-radius: 0.2rem;
            margin-bottom: 1rem;
            border: 2px solid #bed1fb;
        }

        .business-info {
            flex: 5;
        }

        .business-sum {
            flex: 1;
            position: relative;
        }

        .business-info div {
            margin-bottom: 0.2rem;
        }

        .business-item-lg {
            color: #333;
            font-size: 0.8rem;
        }

        .business-item-bold {
            font-weight: bold;
        }

        .notPay-status {
            color: #ef602e;
        }

        .account-money {
            color: #ff6a5f;
            font-size: 0.9rem;
            letter-spacing: 0px;
        }

        .reject-btn {
            font-family: Arial, 'Microsoft YaHei';
            color: #fff;
            width: 3.3rem;
            height: 1.5rem;
            border: 0px;
            right: 0;
            bottom: 0.5rem;
            position: absolute;
            border-radius: 0.2rem;
            background-color: #2e72ef;
        }

        .pay-status {
            color: #2e45ef;
        }

        .reject-status {
            color: #37ddcf;
        }

        .check-status {
            color: #f661ff;
        }

        .submit-status {
            color: #c69b18;
        }

        .craft-status {
            color: #01847f;
        }

        .done-status {
            color: # #a437db;
        }

        .business-item-break {
            word-break: break-all;
        }

        .business-info-unNormal {
            flex: 1;
        }

        .result-item-template {
            display: none;
        }

        .check-result-item {
            margin-bottom: 0.1rem !important;
        }
    </style>
</head>
<body>
<div class="main-section">
    <div class="header"></div>
</div>
<script type="text/javascript" src="../assets/js/jquery.js"></script>
<script type="text/javascript" src="../assets/js/config.js"></script>
<script type="text/javascript" src="../assets/js/dropload.js"></script>
<script type="text/javascript" src="../assets/js/common.js"></script>
<script type="text/javascript">
    var count = 0;
    var total;
    var searchData;
    if (localStorage.searchData) {
        searchData = JSON.parse(localStorage.searchData);
    }
    localStorage.searchData = "";
    function render(arg) {
        var deferred = $.Deferred();
        if (searchData) {
            deferred = getDeferred(searchData, arg);
            return deferred.promise();
        }
        $.ajax({
                   /*url:'../assets/js/testData/business.js',*/
                   url: addressUrl + "exactDay_bizInfo",
                   type: 'get',
                   data: getParams(),
                   dataType: 'json',
                   success: function (data) {
                       /*deferred = getDeferred(data, arg);*/
                       var result = data;
                       $(".header").text(result.date);
                       if (result.error == "0") {
                           var len = result.content.length;
                           var limitLen = (2 * (1 + arg) < len) ? (2 * (1 + arg)) : len;
                           for (var i = 2 * arg; i < limitLen; i++) {
                               /*var unNormalHtml=(result.content[i].biz_state=='驳回'||result.content[i].biz_state=='查验')?("business-info-unNormal"):"";*/
                               var unNormalHtml = (result.content[i].biz_state_en == 'submit') ? ""
                                   : ("business-info-unNormal");
                               var bizState = (result.content[i].pay_state_code == '0')
                                   ? (result.content[i].pay_state)
                                   : result.content[i].biz_state;
                               var bizStateEn = (result.content[i].pay_state_code == '0')
                                   ? ("notPay") : result.content[i].biz_state_en;
                               var limitContainerNoArr = (result.content[i].container_no.split(
                                   ","));
                               var limitContainerNo = (limitContainerNoArr.length == 1)
                                   ? limitContainerNoArr[0] : limitContainerNoArr[0] + "等（"
                                                              + limitContainerNoArr.length + "个柜）";
                               var html = "<div class=\"result-item\">" +
                                          "<div class='business-info" + " " + unNormalHtml + "'>" +
                                          "<div class=\"business-item-lg business-item-bold\">" +
                                          "<label>集装箱号:</label>" + limitContainerNo +
                                          "<input type=\"hidden\" value=" + result.content[i].id
                                          + ">" +
                                          "</div>" +
                                          "<div class=\"business-item-lg\">" +
                                          "<label>业务编号:</label>" + result.content[i].business_id +
                                          "</div>" +
                                          "<div class=\"business-item-lg\">" +
                                          "<label>合同协议号:</label>" + result.content[i].contact_no +
                                          "</div>" +
                                          "<div class=\"business-item-sm\">" +
                                          "<label>进出口类型:</label>" + result.content[i].ie_type +
                                          "</div>" +
                                          "<div class=\"business-item-sm\">" +
                                          "<label>收发货人:</label>"
                                          + result.content[i].consigneeOrConsignor +
                                          "</div>" +
                                          "<div class=\"business-item-sm\">" +
                                          "<label>申报报关行:</label>" + result.content[i].supplier +
                                          "</div>" +
                                          "<div class=\"business-item-sm\">" +
                                          "<label>业务状态:</label>" +
                                          "<span class=\"" + bizStateEn + "-status\">" + bizState +
                                          "</span>" +
                                          "</div>";
                               if (result.content[i].biz_state_en == "reject") {
                                   var rejectReason = result.content[i].reject_reason;
                                   if (!rejectReason) {
                                       rejectReason = "";
                                   }
                                   var rejectHtml = "<div class=\"business-item-sm business-item-bold business-item-break\">"
                                                    +
                                                    "<label>驳回原因:</label>"
                                                    + rejectReason +
                                                    "</div>" +
                                                    "</div>" +
                                                    "</div>";
                                   html += rejectHtml;
                               } else if (result.content[i].biz_state_en == "check") {
                                   var checkResultHtml = "";
                                   var checkResult = result.content[i].check_info.check_results;
                                   for (var j = 0; j < checkResult.length; j++) {
                                       checkResultHtml +=
                                           "<div class=\"check-result-item\">时间:"
                                           + checkResult[j].time
                                           +
                                           "</div>" +
                                           "<div class=\"check-result-item\">状态:"
                                           + checkResult[j].state
                                           +
                                           "</div>" +
                                           "<div class=\"check-result-item\">结果:"
                                           + checkResult[j].text
                                           +
                                           "</div>";
                                   }
                                   var checkHtml = "<div class=\"business-item-sm\">" +
                                                   "<label>查验单位:</label>"
                                                   + result.content[i].check_info.check_depts +
                                                   "</div>" +
                                                   "<div class=\"business-item-sm\">" +
                                                   "<label>查验项目:</label>"
                                                   + result.content[i].check_info.check_items +
                                                   "</div>" +
                                                   "<div class=\"business-item-sm  business-item-break\">"
                                                   +
                                                   "<label>查验记录:</label>" + checkResultHtml +
                                                   "</div>" +
                                                   "</div>" +
                                                   "</div>";
                                   html += checkHtml;
                               } else if ((result.content[i].biz_state_en == "submit")
                                          && (result.content[i].pay_state_code == "0")) {
                                   var businessSumHtml = "<div class=\"business-sum\">" +
                                                         "<div class=\"account-money\">"
                                                         + result.content[i].fee +
                                                         "</div>" +
                                                         /*"<button type=\"button\" class=\"reject-btn\">申请驳回"
                                                          +
                                                          "</button>" +*/
                                                         "</div>" +
                                                         "</div>";
                                   html += "</div>" + businessSumHtml;
                               } else if (result.content[i].biz_state_en == "submit") {
                                   var businessSumHtml = "<div class=\"business-sum\">" +
                                                         "<button type=\"button\" class=\"reject-btn\">申请驳回"
                                                         +
                                                         "</button>" +
                                                         "</div>" +
                                                         "</div>";
                                   html += "</div>" + businessSumHtml;
                               }
                               /*$(".main-section").append(html);*/
                               if (arg == 0) {
                                   $(".main-section").append(html);
                               } else {
                                   $(".dropload-down").before(html.replace(/undefined/g, ""));
                               }
                           }
                           deferred.resolve(len);
                       } else {
                           deferred.reject("暂时没有查询到业务");
                       }

                   },
                   error: function (a, b, c) {
                       alert(b);
                   }
               });
        return deferred.promise();
    }
    $(document).ready(function () {
        render(count++).then(function (arg) {
            total = arg;
            var dropload = $('.main-section').dropload({
                                                           scrollArea: window,
                                                           domDown: {
                                                               domClass: 'dropload-down',
                                                               domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
                                                               domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
                                                               domNoData: '<div class="dropload-noData">已无数据</div>'
                                                           },
                                                           loadDownFn: function (me) {
                                                               setTimeout(function () {
                                                                   if (count > Math.ceil((total - 2)
                                                                                         / 2)) {
                                                                       me.resetload();
                                                                       me.lock();
                                                                       me.noData();
                                                                       me.resetload();
                                                                       return;
                                                                   }
                                                                   render(count++);
                                                                   me.resetload();
                                                               }, 1000)
                                                           }
                                                       });
        }, function (arg) {
            window.location.href = "brokedown.html";
        });
        $(".main-section").on("click", ".reject-btn", function () {
            var idVal = $(this).parents(".business-sum").prev(".business-info").find("input").val();
            window.location.href = "applyReject.html?id=" + idVal;
        });
    });
    function getDeferred(searchData, arg) {
        var deferred = $.Deferred();
        var result = searchData;
        $(".header").text(result.date);
        if (result.error == "0") {
            var len = result.content.length;
            var limitLen = (2 * (1 + arg) < len) ? (2 * (1 + arg)) : len;
            for (var i = 2 * arg; i < limitLen; i++) {
                var unNormalHtml = (result.content[i].biz_state_en == 'submit') ? ""
                    : ("business-info-unNormal");
                var bizState = (result.content[i].pay_state_code == '0')
                    ? (result.content[i].pay_state)
                    : result.content[i].biz_state;
                var bizStateEn = (result.content[i].pay_state_code == '0')
                    ? ("notPay") : result.content[i].biz_state_en;
                var html = "<div class=\"result-item\">" +
                           "<div class='business-info" + " " + unNormalHtml + "'>" +
                           "<div class=\"business-item-lg business-item-bold\">" +
                           "<label>集装箱号:</label>" + result.content[i].container_no +
                           "<input type=\"hidden\" value=" + result.content[i].id
                           + ">" +
                           "</div>" +
                           "<div class=\"business-item-lg\">" +
                           "<label>业务编号:</label>" + result.content[i].business_id +
                           "</div>" +
                           "<div class=\"business-item-lg\">" +
                           "<label>合同协议号:</label>" + result.content[i].contact_no +
                           "</div>" +
                           "<div class=\"business-item-sm\">" +
                           "<label>进出口类型:</label>" + result.content[i].ie_type +
                           "</div>" +
                           "<div class=\"business-item-sm\">" +
                           "<label>收发货人:</label>"
                           + result.content[i].consigneeOrConsignor +
                           "</div>" +
                           "<div class=\"business-item-sm\">" +
                           "<label>申报报关行:</label>" + result.content[i].supplier +
                           "</div>" +
                           "<div class=\"business-item-sm\">" +
                           "<label>业务状态:</label>" +
                           "<span class=\"" + bizStateEn + "-status\">" + bizState +
                           "</span>" +
                           "</div>";
                if (result.content[i].biz_state_en == "reject") {
                    var rejectHtml = "<div class=\"business-item-sm business-item-bold business-item-break\">"
                                     +
                                     "<label>驳回原因:</label>"
                                     + result.content[i].reject_reason +
                                     "</div>" +
                                     "</div>" +
                                     "</div>";
                    html += rejectHtml;
                } else if (result.content[i].biz_state_en == "check") {
                    var checkResultHtml = "";
                    var checkResult = result.content[i].check_info.check_results;
                    for (var j = 0; j < checkResult.length; j++) {
                        checkResultHtml +=
                            "<div class=\"check-result-item\">时间:"
                            + checkResult[j].time
                            +
                            "</div>" +
                            "<div class=\"check-result-item\">状态:"
                            + checkResult[j].state
                            +
                            "</div>" +
                            "<div class=\"check-result-item\">结果:"
                            + checkResult[j].text
                            +
                            "</div>";
                    }
                    var checkHtml = "<div class=\"business-item-sm\">" +
                                    "<label>查验单位:</label>"
                                    + result.content[i].check_info.check_depts +
                                    "</div>" +
                                    "<div class=\"business-item-sm\">" +
                                    "<label>查验项目:</label>"
                                    + result.content[i].check_info.check_items +
                                    "</div>" +
                                    "<div class=\"business-item-sm  business-item-break\">"
                                    +
                                    "<label>查验记录:</label>" + checkResultHtml +
                                    "</div>" +
                                    "</div>" +
                                    "</div>";
                    html += checkHtml;
                } else if ((result.content[i].biz_state_en == "submit")
                           && (result.content[i].pay_state_code == "0")) {
                    var businessSumHtml = "<div class=\"business-sum\">" +
                                          "<div class=\"account-money\">"
                                          + result.content[i].fee +
                                          "</div>" +
                                          "</div>" +
                                          "</div>";
                    html += "</div>" + businessSumHtml;
                } else if (result.content[i].biz_state_en == "submit") {
                    var businessSumHtml = "<div class=\"business-sum\">" +
                                          "<button type=\"button\" class=\"reject-btn\">申请驳回"
                                          +
                                          "</button>" +
                                          "</div>" +
                                          "</div>";
                    html += "</div>" + businessSumHtml;
                }
                if (arg == 0) {
                    $(".main-section").append(html);
                } else {
                    $(".dropload-down").before(html.replace(/undefined/g, ""));
                }
            }
            deferred.resolve(len);
        } else {
            deferred.reject("暂时没有查询到业务");
        }
        return deferred;
    }
</script>
</body>
</html>